package client;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.rmi.Remote;
import java.rmi.RemoteException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import adapter.IAdapter;
import factory.Factory;

public class ImagePanel extends JPanel implements Remote {
	private static final long serialVersionUID = 0L;

	private BufferedImage image;

	public ImagePanel() {
		try {                
			image = ImageIO.read(new File("resources/flughafen.png"));
		} catch (IOException ex) {
		}
	}

	@Override
	public void paintComponent(Graphics g) {
		IAdapter adapter = Factory.getAdapter(this);

		g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
		g.setFont(new Font("TimesRoman", Font.PLAIN, 16));
		try {
			g.setColor( (adapter.getStartLandebahn(1).isFree())?Color.GREEN:Color.RED );
			g.drawString("Start - Landebahn 1", 5, 35);
			g.setColor( (adapter.getStartLandebahn(2).isFree())?Color.GREEN:Color.RED );
			g.drawString("Start - Landebahn 2", 5, 60);
			g.setColor( (adapter.getStartLandebahn(3).isFree())?Color.GREEN:Color.RED );
			g.drawString("Start - Landebahn 3", 5, 85);
			g.setColor( (adapter.getStartLandebahn(4).isFree())?Color.GREEN:Color.RED );
			g.drawString("Start - Landebahn 4", 5, 110);
			g.setColor(Color.GREEN);
			g.drawString("Hangar 1", 170, 320);
			g.setColor(Color.GREEN);
			g.drawString("Hangar 2", 250, 320);

			g.setFont(new Font("TimesRoman", Font.BOLD, 20));

			g.setColor( (adapter.getParkposition(1).isFree())?Color.GREEN:Color.RED );
			g.drawString("P1", 345, 230);
			g.setColor( (adapter.getParkposition(2).isFree())?Color.GREEN:Color.RED );
			g.drawString("P2", 345, 260);
			g.setColor( (adapter.getParkposition(3).isFree())?Color.GREEN:Color.RED );
			g.drawString("P3", 390, 230);
			g.setColor( (adapter.getParkposition(4).isFree())?Color.GREEN:Color.RED );
			g.drawString("P4", 390, 260);
			g.setColor( (adapter.getParkposition(5).isFree())?Color.GREEN:Color.RED );
			g.drawString("P5", 440, 230);
			g.setColor( (adapter.getParkposition(6).isFree())?Color.GREEN:Color.RED );
			g.drawString("P6", 440, 260);
			g.setColor( (adapter.getParkposition(7).isFree())?Color.GREEN:Color.RED );
			g.drawString("P7", 490, 230);
			g.setColor( (adapter.getParkposition(8).isFree())?Color.GREEN:Color.RED );
			g.drawString("P8", 490, 260);
			g.setColor( (adapter.getParkposition(9)).isFree()?Color.GREEN:Color.RED );
			g.drawString("P9", 540, 230);
			g.setColor( (adapter.getParkposition(10).isFree())?Color.GREEN:Color.RED );
			g.drawString("PA", 540, 260);
			g.setColor( (adapter.getParkposition(11).isFree())?Color.GREEN:Color.RED );
			g.drawString("PB", 585, 230);
			g.setColor( (adapter.getParkposition(12).isFree())?Color.GREEN:Color.RED );
			g.drawString("PC", 585, 260);
		} catch (RemoteException re) {
			re.printStackTrace();
		}
	}
}